package com.xtx.controller.user;

import com.xtx.dto.OrderDto;
import com.xtx.dto.PayDto;
import com.xtx.result.Result;
import com.xtx.service.PayService;
import com.xtx.vo.PayOrderVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/member")
@Slf4j
public class PayController {

    @Autowired
    private PayService payService;

    @PostMapping("/order")
    public Result<PayOrderVo> payOrder(@RequestBody OrderDto orderDto){
        log.info("用户下单"+orderDto);
        return Result.success(payService.getPayOrder(orderDto));
    }
    @GetMapping("/order/{id}")
    public Result<PayOrderVo> getPayOrder(@PathVariable String id){
        log.info("查询订单"+id);
        return Result.success(payService.getPayOrderByOrderId(id));
    }
    @PostMapping("/pay")
    public Result pay(@RequestBody PayDto payDto){
        log.info("支付"+payDto);
        return payService.pay(payDto);
    }
    @PutMapping("/order/{id}")
    public Result cancelOrder(@PathVariable String id){
        log.info("取消订单"+id);
        payService.cancelOrder(id);
        return Result.success();
    }
}
